var Class = {
	create: function()
	{
		return function()
		{
			this.initialize.apply(this,arguments);
		}
	}
}
Object.prototype.extend=function(object)
{
	for (property in object)
		this[property]=object[property];
	return this;
}
Function.prototype.bind=function(object)
{
	var method=this;
	return function()
	{
		method.apply(object,arguments);
	}
}
var Try = {
	these: function()
	{
		var returnValue;
		for (var i=0;i<arguments.length;i++)
		{
			var lambda=arguments[i];
			try {
				returnValue=lambda();
				break;
			} catch(e) {}
		}
		return returnValue;
	}
}
function $()
{
	var elements=new Array();
	for (var i=0;i<arguments.length;i++)
	{
		var element=arguments[i];
		if (typeof element=='string')
			element=document.getElementById(element);
		if (arguments.length==1)
			return element;
		elements.push(element);
	}
	return elements;
}

var Ajax = {
	getTransport: function()
	{
		return Try.these(
			function(){return new ActiveXObject('Msxml2.XMLHTTP')},
			function(){return new ActiveXObject('Microsoft.XMLHTTP')},
			function(){return new XMLHttpRequest()}
		) || false;
	},
	emptyFunction: function() {}
}
Ajax.Base = function() {};
Ajax.Base.prototype = {
	setOptions: function(options)
	{
		this.options={
			method: 'post',
			parameters: ''
		}.extend(options || {});
	}
}
Ajax.Request = Class.create();
Ajax.Request.Events =
	['Uninitialized','Loading','Loaded','Interactive','Complete'];

Ajax.Request.prototype = (new Ajax.Base()).extend({
	initialize: function(url,options)
	{
		this.transport=Ajax.getTransport();
		this.setOptions(options)
		try {
			if (this.options.method=='get')
				url+='?'+this.options.parameters+'&_=';
			this.transport.open(this.options.method,url,true);
			this.transport.onreadystatechange=this.onStateChange.bind(this);
			setTimeout((function() {this.respondToReadyState(1)}).bind(this),10);
			if (this.options.method=='post')
			{
				this.transport.setRequestHeader('Connection','close');
				this.transport.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			}
			this.transport.send(this.options.method=='post'?this.options.parameters+'&_=':null);
		} catch(e) {}
	},
	onStateChange: function()
	{
		var readyState=this.transport.readyState;
		if (readyState!=1)
			this.respondToReadyState(this.transport.readyState);
	},
	respondToReadyState: function(readyState)
	{
		var event=Ajax.Request.Events[readyState];
		(this.options['on'+event] || Ajax.emptyFunction)(this.transport);
	}
});

function cumulativeOffset(element)
{
	var t=0,l=0;
	do {
		t+=element.offsetTop ||0;
		l+=element.offsetLeft ||0;
		element=element.offsetParent;
	} while (element);
	return [l,t];
}

document.getElementsByClassName=function(className)
{
	var children=document.getElementsByTagName('*') || document.all;
	var elements=new Array();
	for (var i=0;i<children.length;i++)
	{
		var child=children[i];
		var classNames=child.className.split(' ');
		for (var j=0;j<classNames.length;j++)
		{
			if (classNames[j]==className)
			{
				elements.push(child);
				break;
			}
		}
	}
	return elements;
}
